/**
 * Project Name:HomeActivity
 * Date:2016-3-17下午8:55:00
 * Copyright (c) 2016, askzhao All Rights Reserved.
 *
 */
package com.kkd.kkdapp.activity;

import java.lang.ref.WeakReference;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

import org.json.JSONException;
import org.json.JSONObject;

import android.animation.Animator;
import android.animation.Animator.AnimatorListener;
import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.Editable;
import android.text.Selection;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.AlphaAnimation;
import android.view.inputmethod.EditorInfo;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;

import com.google.gson.reflect.TypeToken;
import com.kkd.kkdapp.R;
import com.kkd.kkdapp.db.app.model.User;
import com.kkd.kkdapp.http.entity.BankData;
import com.kkd.kkdapp.http.entity.CardItem;
import com.kkd.kkdapp.http.entity.HomeData;
import com.kkd.kkdapp.http.entity.JiangXiSetPasswordData;
import com.kkd.kkdapp.http.entity.TrueIDVerifyData;
import com.kkd.kkdapp.http.entity.TyjConfigEntity;
import com.kkd.kkdapp.http.manager.HttpCallBack;
import com.kkd.kkdapp.http.manager.KkdHttpMagager;
import com.kkd.kkdapp.listener.OnSingleClickListener;
import com.kkd.kkdapp.utils.AppUtil;
import com.kkd.kkdapp.utils.CardNumberType;
import com.kkd.kkdapp.utils.DialogUtils;
import com.kkd.kkdapp.utils.LogUtil;
import com.kkd.kkdapp.utils.PreferenceUtils;
import com.kkd.kkdapp.utils.SystemUtils;
import com.kkd.kkdapp.view.RiseProgressBar;
import com.nostra13.universalimageloader.core.ImageLoader;

/**
 * ClassName: ForTenderActivity <br/>
 * date: 2016-3-17 下午8:55:00 <br/>
 * 
 * @author askzhao
 * @version
 */
public class ForTenderActivity extends BankBaseActivity {
	private int enterTypeFlag = 1;
	private Context mContext = this;
	private Dialog mDialog2;
	private Dialog supriseDialog;
	private Dialog dialog1;
	private Dialog toLoadDialog;
	private View add_bankcard;
	private View toJiangXiBank;
	private LinearLayout add_success_line;
	private EditText truth_ed; // 真实姓名
	private EditText card_ed; // 身份证号
	private RelativeLayout back; // 返回键
	private TextView step1_tv;
	private TextView step2_tv;
	private ImageView step3_tv;
	private TextView desc_tv;
	private RiseProgressBar mProgressbar;

	private final int ADDBAND_CODE_ZERO = 1; // 添加银行卡code=0
	private final int READ_NOTE = 2; // 读取短信
	private final int ADDBAND_CODE_ELSE = 3; // 添加银行卡code=其它
	private final int ADDBANKVERIFICATION_CODE_ZERO = 4; // 添加银行卡发送验证码code=0
	private final int ADDBANKVERIFICATION_CODE_ELSE = 5; // 添加银行卡发送验证码code=其它
	private final int SETPASS_CODE_SUC = 5001;
	private final int SETPASS_CODE_ELSE = 5002;
	private final int TRUE_ID_SUCCESS = 6; // 实名成功
	private final int TO_FINISH = 7;
	private final int TRUE_ID_FAILURE = 8;
	private final int UPDATE_UI = 9;
	private Button add_bankCard_bt; //
	private EditText card_numbered; // 银行卡号
	private String cardName = null; // 银行名字
	private RelativeLayout support_bank; // 提示
	private TextView card_obligate_numbered; // 预留手机号
	private EditText card_verify_ed; // 手机验证码
	private String ticket; // 验证信息/绑卡推进时使用
	private String srvAuthCode;
	private String bindingId; // 绑定卡id/绑卡推进时使用
	private boolean flag = true;
	private TextView cardname_tv;
	private RelativeLayout card_rl;
	private ImageView card_img;// 银行图标
	private ImageView card_type; // 银行卡类型
	private TextView mXianEDesc;// 限额说明
	private ImageView trueid_iv;
	private ImageView bank_iv;
	private String cardtype;
	private RelativeLayout support_phone;
	private TimerTask mTimerTask;
	private Timer timer;
	private int time;
	private RelativeLayout send_verify; // 发送验证码
	private TextView verfition_visibility;
	private TextView count_tv;
	private TextView count_down;
	private String bankCode = null; // 银行编号
	private String strContent;
	private TextView mCard_hint;
	private TextView tip_tv;
	private Dialog mDialog;
	private RelativeLayout mContentView;
	private RelativeLayout tip_rl;
	private HomeData mHomeData;
	private boolean isHome;
	private String title;
	private String surplus;
	private String yuebaoid;
	private long lowestAmount;
	private double rates;
	private String interests;
	private boolean isShowDialogTip;
	private String bidId;
	private String bidTitle;
	private int bidPeriod;
	private long amountMultiple; // 倍数
	private String bidPeriodType; // 期限单位
	private String bidInterest; // 年利率
	private long bidFreeAmount;
	private long maxAmount;
	private long bidAmount;
	private long totalLixi;
	private String bidType;
	private String businessType;
	private int productType;
	private String bincardUrl;
	private String realnameUrl;
	private ImageView icon1;
	private ImageView icon2;
	private List<CardItem> cardList;
	private String bidPeriodWeb; // 期限
	private int bidPeriodAdd;
	private String newMisTips; // 是否处于新手任务
	private long timeSpace; // 是否显示新手任务
	private boolean isFromRegister = false; // 是否来自于注册页面的跳转
	private Dialog dialog_registerSuccess; // 注册成功的dialog
	private boolean isAdded = false;
	private String poi_pre_reward_image;
	private String poi_pre_reward_image2;
	private String cardNo; // 银行卡号
	private String poiPreMisPacketTips; // 最后一步的提示
	private int isNewbie;
	private String json; // 债权转让详情

	private String name_param = "";// 姓名
	private String idCard_param = "";// 身份证号
	private String bankCard_param = "";// 银行卡号

	private Handler mHandler = new Handler() {
		public void handleMessage(android.os.Message msg) {

			String desc = "";

			switch (msg.what) {
			case ADDBAND_CODE_ZERO: // 添加银行卡code=0
				PreferenceUtils.getInstance().setBoundBankCard(
						ForTenderActivity.this, 1);
				// bank_iv.setImageResource(R.drawable.success_5000);
				getOther();
				dismissLoadIng();
				toStateAddedBank();
				desc = (String) msg.obj;
				if (TextUtils.isEmpty(desc)) {
					desc_tv.setVisibility(View.GONE);
				} else {
					desc_tv.setVisibility(View.VISIBLE);
					desc_tv.setText(desc);
				}
				PreferenceUtils.getInstance().setCardNo(ForTenderActivity.this,
						cardNo);
				break;
			case READ_NOTE: // 读取短信
				card_verify_ed.setText(strContent);
				break;
			case ADDBAND_CODE_ELSE: // 添加银行卡code=其它
				desc = (String) msg.obj;
				dismissLoadIng();
				showToast(desc);
				break;
			case ADDBANKVERIFICATION_CODE_ZERO: // 添加银行卡发送验证码code=0
				showToast(R.string.note_message);
				break;
			case ADDBANKVERIFICATION_CODE_ELSE: // 添加银行卡发送验证码code=其它
				desc = (String) msg.obj;
				showToast(desc);
				// send_verify.setBackgroundResource(R.drawable.addbank_bg_tv);
				verfition_visibility.setTextColor(0xff6c54b6);
				verfition_visibility.setVisibility(View.VISIBLE);
				count_down.setVisibility(View.GONE);
				count_tv.setVisibility(View.GONE);
				flag = true;
				if (mTimerTask != null) {
					mTimerTask.cancel();
					mTimerTask = null;
				}
				break;
			case TRUE_ID_SUCCESS:
				PreferenceUtils.getInstance().setBoundBankCard(
						ForTenderActivity.this, 1);
				PreferenceUtils.getInstance().setCardNo(ForTenderActivity.this,
						bankCard_param);
				User.updateCardId(idCard_param);
				User.updaterealName(name_param);
				PreferenceUtils.getInstance().setAutonym(
						ForTenderActivity.this, 1);
				PreferenceUtils.getInstance().setIdCardAndRealName(
						ForTenderActivity.this, idCard_param, name_param);
				getOther();
				dismissLoadIng();
				toStateSetPassword();
				showTipForTrueIdSucess();
				break;
			case TRUE_ID_FAILURE:
				dismissLoadIng();
				desc = (String) msg.obj;
				showToast(desc);
				break;
			case TO_FINISH:
				finish();

				Intent intent_toFinish = new Intent(mContext,
						FinishBeforeTenderActivity.class);
				intent_toFinish.putExtra("isHaveNewTask",
						!TextUtils.isEmpty(newMisTips)); // 说明是否有新手任务
				intent_toFinish.putExtra("isShowDialogTip", isShowDialogTip);
				intent_toFinish.putExtra("enterTypeFlag", enterTypeFlag);
				intent_toFinish.putExtra("poi_pre_reward_image",
						poi_pre_reward_image);
				intent_toFinish.putExtra("poi_pre_reward_image2",
						poi_pre_reward_image2);
				if (enterTypeFlag == 4) {
					intent_toFinish.putExtra("title", title);
					intent_toFinish.putExtra("surplus", surplus);
					intent_toFinish.putExtra("yuebaoid", yuebaoid);
					intent_toFinish.putExtra("lowestAmount", lowestAmount);
					intent_toFinish.putExtra("rates", rates);
					intent_toFinish.putExtra("interests", interests);
					intent_toFinish.putExtra("url_xieYi", url_xieYi);
					intent_toFinish.putExtra("title_xieYi", title_xieYi);
				} else if (enterTypeFlag == 5) {
					intent_toFinish.putExtra("bidId", bidId);
					intent_toFinish.putExtra("bidTitle", bidTitle);
					intent_toFinish.putExtra("bidPeriod", bidPeriod);
					intent_toFinish.putExtra("amountMultiple", amountMultiple);
					intent_toFinish.putExtra("lowestAmount", lowestAmount);
					intent_toFinish.putExtra("bidPeriodType", bidPeriodType);
					intent_toFinish.putExtra("bidInterest", bidInterest);
					intent_toFinish.putExtra("bidFreeAmount", bidFreeAmount);
					intent_toFinish.putExtra("maxAmount", maxAmount);
					intent_toFinish.putExtra("bidAmount", bidAmount);
					intent_toFinish.putExtra("totalLixi", totalLixi);
					intent_toFinish.putExtra("bidType", bidType);
					intent_toFinish.putExtra("businessType", businessType);
					intent_toFinish.putExtra("productType", productType);
					intent_toFinish.putExtra("bidPeriodWeb", bidPeriodWeb);
					intent_toFinish.putExtra("bidPeriodAdd", bidPeriodAdd);
					intent_toFinish.putExtra("isNewbie", isNewbie);
				} else if (enterTypeFlag == 6) { // 债权转让购买
					intent_toFinish.putExtra("json", json);
				}
				startActivity(intent_toFinish);
				break;
			case UPDATE_UI:
				updateUI();

				break;

			case SETPASS_CODE_SUC:
				Intent intent = new Intent(ForTenderActivity.this,
						KKDJiangXiWebActivity.class);
				intent.putExtra("url", "");
				intent.putExtra("data", msg.obj.toString());
				intent.putExtra("useTitleName", true);
				intent.putExtra("titleName", "设置交易密码");
				startActivityForResult(intent, KKDJiangXiWebActivity.SET_PWD);
				break;
			case SETPASS_CODE_ELSE:
				AppUtil.makeToastForCustomer(ForTenderActivity.this,
						(String) msg.obj);
				break;
			default:
				break;

			}
		}

	};
	private String url_xieYi;
	private String title_xieYi;
	private View rel_new_task;
	private TextView tv_time_newTask;
	private TextView textView1;
	private RelativeLayout rel_toStateBankcard;
	private View agreement_tv2;
	private View agreement_tv4;

	public void showTipAnimTranslate() {
		ObjectAnimator animation;
		PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat(
				"translationY", 0, SystemUtils.dip2px(this, 60), 0);
		tip_rl.setVisibility(View.VISIBLE);

		animation = ObjectAnimator.ofPropertyValuesHolder(tip_rl, pvhY);
		animation.setDuration(4000);
		animation.addListener(new AnimatorListener() {

			@Override
			public void onAnimationStart(Animator animation) {

			}

			@Override
			public void onAnimationRepeat(Animator animation) {

			}

			@Override
			public void onAnimationEnd(Animator animation) {
				tip_rl.setVisibility(View.GONE);
			}

			@Override
			public void onAnimationCancel(Animator animation) {

			}
		});
		animation.start();
	}

	/**
	 * updateUI:(这里用一句话描述这个方法的作用). <br/>
	 * 
	 * @author askzhao
	 */
	protected void updateUI() {
		mHomeData = PreferenceUtils.getInstance().getHomeData2(
				ForTenderActivity.this);
		if (mHomeData != null) {
			bincardUrl = mHomeData.getOther().getBincardUrl();
			realnameUrl = mHomeData.getOther().getRealnameUrl();
		}
		if (mHomeData != null) {
			if (!TextUtils.isEmpty(mHomeData.getOther().getRealnameAmount())) {
				tip_tv.setText("白拿" + mHomeData.getOther().getRealnameAmount()
						+ "特权本金");

			} else {
				trueid_iv.setVisibility(View.GONE);
			}
			if (!TextUtils.isEmpty(mHomeData.getOther().getBincardAmount())
					&& mHomeData.getOther().getIsHaveBinCard() == 0) {
				// add_bankCard_bt.setText("绑卡领取"
				// + mHomeData.getOther().getBincardAmount() + "特权本金");

			} else {
				bank_iv.setVisibility(View.GONE);
			}
			if (!TextUtils.isEmpty(bincardUrl)) {
				bank_iv.setVisibility(View.VISIBLE);
				ImageLoader.getInstance().displayImage(bincardUrl, bank_iv);
			} else {
				bank_iv.setVisibility(View.GONE);
			}
			if (!TextUtils.isEmpty(realnameUrl)) {
				trueid_iv.setVisibility(View.VISIBLE);
				ImageLoader.getInstance().displayImage(realnameUrl, trueid_iv);
			} else {
				trueid_iv.setVisibility(View.GONE);
			}
		}
		if (TextUtils.isEmpty(poiPreMisPacketTips)) {
			textView1.setText("完成");
		} else {
			textView1.setText(poiPreMisPacketTips);
		}
		// 说明处于新手任务阶段
		if (TextUtils.isEmpty(newMisTips)) { // 说明没有新手任务
			rel_new_task.setVisibility(View.GONE);
			// textView1.setText("完成");
			if (isAdded) {
				step3_tv.setBackgroundResource(R.drawable.add_bank_round_y1);
			} else {
				step3_tv.setBackgroundResource(R.drawable.add_bank_round_g1);
			}
		} else {
			rel_new_task.setVisibility(View.VISIBLE);
			// tv_time_newTask.setText(newMisTips);
			updateNewTaskSpaceTime();
			startTime();
			// textView1.setText("10元红包");
			if (isAdded) {
				step3_tv.setBackgroundResource(R.drawable.icon_fortender_newtask_red);
			} else {
				step3_tv.setBackgroundResource(R.drawable.icon_fortender_newtask_gray);
			}
		}
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		getOther();
		setContentView(R.layout.activity_fortender);
		getMessage();
		initView();
		setListener();
		showRegisterSuccessDialog();
	}

	private void showRegisterSuccessDialog() {
		if (isFromRegister) {
			String regSuccessImage = getIntent().getStringExtra(
					"regSuccessImage");
			if (dialog_registerSuccess != null) {
				dialog_registerSuccess.cancel();
				dialog_registerSuccess = null;
			}
			dialog_registerSuccess = DialogUtils.registerSuccessDialog(
					mContext, regSuccessImage);
			dialog_registerSuccess.show();
		}
	}

	private void getMessage() {
		Intent intent = getIntent();
		isShowDialogTip = intent.getBooleanExtra("isShowDialogTip", false);
		enterTypeFlag = intent.getIntExtra("enterTypeFlag", -1);
		if (enterTypeFlag == 4) {
			title = intent.getStringExtra("title");
			surplus = intent.getStringExtra("surplus");
			yuebaoid = intent.getStringExtra("yuebaoid");
			lowestAmount = intent.getLongExtra("lowestAmount", 0);
			rates = intent.getDoubleExtra("rates", 0);
			interests = intent.getStringExtra("interests");
			url_xieYi = intent.getStringExtra("url_xieYi");
			title_xieYi = intent.getStringExtra("title_xieYi");
		} else if (enterTypeFlag == 5) {
			bidId = intent.getStringExtra("bidId");
			bidTitle = intent.getStringExtra("bidTitle");
			bidPeriod = intent.getIntExtra("bidPeriod", 0);
			amountMultiple = intent.getLongExtra("amountMultiple", 0);
			lowestAmount = intent.getLongExtra("lowestAmount", 0);
			bidPeriodType = intent.getStringExtra("bidPeriodType");
			bidInterest = intent.getStringExtra("bidInterest");
			bidFreeAmount = intent.getLongExtra("bidFreeAmount", 0);
			maxAmount = intent.getLongExtra("maxAmount", 0);
			bidAmount = intent.getLongExtra("bidAmount", 0);
			totalLixi = intent.getLongExtra("totalLixi", 0);
			bidType = intent.getStringExtra("bidType");
			businessType = intent.getStringExtra("businessType");
			productType = intent.getIntExtra("productType", -1);
			bidPeriodWeb = intent.getStringExtra("bidPeriodWeb");
			bidPeriodAdd = intent.getIntExtra("bidPeriodAdd", 0);
			isNewbie = intent.getIntExtra("isNewbie", -1);
		} else if (enterTypeFlag == 6) { // 债权转让购买
			json = intent.getStringExtra("json");
		}
		isFromRegister = intent.getBooleanExtra("isFromRegister", false); // 是否来自于注册页的跳转
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.kkd.kkdapp.base.BaseActivity#onResume()
	 */
	@Override
	protected void onResume() {
		super.onResume();
		questCardList();
		bankCardNumAddSpace(card_numbered);
	}

	public void initView() {
		// 《江西银行网络交易资金账户服务三方协议》
		agreement_tv2 = findViewById(R.id.agreement_tv2);
		agreement_tv2.setOnClickListener(mOnSingleClickListener);
		// 《用户授权协议》
		agreement_tv4 = findViewById(R.id.agreement_tv4);
		agreement_tv2.setOnClickListener(mOnSingleClickListener);
		// 顶部的新手任务提示
		rel_toStateBankcard = (RelativeLayout) findViewById(R.id.rel_toStateBankcard);
		rel_new_task = findViewById(R.id.rel_new_task);
		tv_time_newTask = (TextView) findViewById(R.id.tv_time_newTask);
		textView1 = (TextView) findViewById(R.id.textView1);
		bank_iv = (ImageView) findViewById(R.id.bank_iv);
		step1_tv = (TextView) findViewById(R.id.step1_tv);
		step2_tv = (TextView) findViewById(R.id.step2_tv);
		step3_tv = (ImageView) findViewById(R.id.step3_tv);
		mProgressbar = (RiseProgressBar) findViewById(R.id.progressbar);
		mProgressbar.setMax(1000);
		mProgressbar.withNumber(250);
		mProgressbar.start();
		add_bankcard = (View) findViewById(R.id.add_bankcard);
		toJiangXiBank = (View) findViewById(R.id.toJiangXiBank);
		add_success_line = (LinearLayout) findViewById(R.id.add_success_line);
		tip_tv = (TextView) findViewById(R.id.tip_tv);
		trueid_iv = (ImageView) findViewById(R.id.trueid_iv);
		bank_iv = (ImageView) findViewById(R.id.bank_iv);
		truth_ed = (EditText) this.findViewById(R.id.truth_ed);
		card_ed = (EditText) this.findViewById(R.id.card_ed);
		desc_tv = (TextView) findViewById(R.id.desc_tv);
		back = (RelativeLayout) this.findViewById(R.id.back);
		add_bankCard_bt = (Button) this.findViewById(R.id.add_bankCard_bt);
		card_numbered = (EditText) this.findViewById(R.id.card_numbered);
		support_bank = (RelativeLayout) this.findViewById(R.id.support_bank);
		card_obligate_numbered = (TextView) this
				.findViewById(R.id.card_obligate_numbered);
		card_verify_ed = (EditText) this.findViewById(R.id.card_verify_ed);
		cardname_tv = (TextView) this.findViewById(R.id.cardname_tv);
		card_rl = (RelativeLayout) this.findViewById(R.id.card_rl);
		card_img = (ImageView) this.findViewById(R.id.card_img);
		card_type = (ImageView) this.findViewById(R.id.card_type);
		support_phone = (RelativeLayout) this.findViewById(R.id.support_phone);
		send_verify = (RelativeLayout) this.findViewById(R.id.send_verify);
		verfition_visibility = (TextView) this
				.findViewById(R.id.verfition_visibility);
		count_tv = (TextView) this.findViewById(R.id.count_tv);
		count_down = (TextView) this.findViewById(R.id.count_down);
		mCard_hint = (TextView) this.findViewById(R.id.card_hint);
		mXianEDesc = (TextView) findViewById(R.id.xiane_desc);
		mContentView = (RelativeLayout) this.findViewById(R.id.ContentView);
		tip_rl = (RelativeLayout) findViewById(R.id.tip_rl);
		add_bankcard.setVisibility(View.VISIBLE);
		toJiangXiBank.setVisibility(View.GONE);
		add_success_line.setVisibility(View.GONE);
		updateUI();

		if (PreferenceUtils.getInstance().getOpenAccount(this) == 1) {
			// 已经开通江西银行账户，设置交易密码
			toStateSetPassword();
		} else {
			mXianEDesc.setVisibility(View.VISIBLE);
		}

		icon1 = (ImageView) this.findViewById(R.id.icon1);
		icon2 = (ImageView) this.findViewById(R.id.icon2);

		card_obligate_numbered.setText(PreferenceUtils.getInstance().getPhone(
				mContext));
		verfition_visibility.setTextColor(0xff6c54b6);
		if (cardList != null) {
			for (int i = 0; i < cardList.size(); i++) {
				if (cardName != null
						&& cardName.equals(cardList.get(i).getBankName())) {
					if (cardList.get(i).getBindCardStatus().equals("0")) {
						verfition_visibility.setTextColor(0xffb5b5b5);
					}
				}
			}
		}
		verfition_visibility.setVisibility(View.VISIBLE);
		count_down.setVisibility(View.GONE);
		count_tv.setVisibility(View.GONE);
		flag = true;
	}

	private void toStateAddedBank() {
		isAdded = true;
		/*
		 * 此处以下为显示小太阳
		 */
		// add_bankcard.setVisibility(View.GONE);
		// mXianEDesc.setVisibility(View.VISIBLE);
		// add_success_line.setVisibility(View.VISIBLE);
		/*
		 * 此处以上为显示小太阳
		 */
		// step1_tv = (TextView) findViewById(R.id.step1_tv);
		// step2_tv = (TextView) findViewById(R.id.step2_tv);
		// step3_tv = (TextView) findViewById(R.id.step3_tv);
		mProgressbar.init();
		mProgressbar.withNumber(1000);
		mProgressbar.setDuration(1000);
		mProgressbar.start();
		if (TextUtils.isEmpty(newMisTips)) { // 说明没有新手任务
			step3_tv.setBackgroundResource(R.drawable.add_bank_round_y1);
		} else {
			step3_tv.setBackgroundResource(R.drawable.icon_fortender_newtask_red);
		}
		// showSupriseDialog();
		mHandler.sendEmptyMessageDelayed(TO_FINISH, 0/* 2000 */);
	};

	public void toStateSetPassword() {
		add_bankcard.setVisibility(View.GONE);
		toJiangXiBank.setVisibility(View.VISIBLE);
		mXianEDesc.setVisibility(View.GONE);
		add_success_line.setVisibility(View.GONE);
		mProgressbar.init();
		mProgressbar.withNumber(750);
		mProgressbar.setDuration(1000);
		mProgressbar.start();
		step2_tv.setBackgroundResource(R.drawable.add_bank_roundn_bank_y);
		setJiangXiPassword();
	}

	public void setListener() {
		back.setOnClickListener(mOnSingleClickListener);

		add_bankCard_bt.setOnClickListener(mOnSingleClickListener);
		support_bank.setOnClickListener(mOnSingleClickListener);
		send_verify.setOnClickListener(mOnSingleClickListener);
		card_rl.setOnClickListener(mOnSingleClickListener);
		support_phone.setOnClickListener(mOnSingleClickListener);
		card_numbered.setOnClickListener(mOnSingleClickListener);
		card_verify_ed.setOnClickListener(mOnSingleClickListener);
		mContentView.setOnClickListener(mOnSingleClickListener);
		card_verify_ed.setOnEditorActionListener(new OnEditorActionListener() {

			@Override
			public boolean onEditorAction(TextView v, int actionId,
					KeyEvent event) {
				if (actionId == EditorInfo.IME_ACTION_DONE) {
					actionAddBankCard();
				}
				return false;
			}
		});
		mXianEDesc.setOnClickListener(mOnSingleClickListener);
	}

	OnSingleClickListener mOnSingleClickListener = new OnSingleClickListener() {

		@Override
		public void onSingleClick(View v) {
			switch (v.getId()) {
			case R.id.back:
				// finish();
				getOther();
				dismissLoadIng();
				toStateSetPassword();
				showTipForTrueIdSucess();
				break;
			case R.id.add_bankCard_bt: // 绑卡
				actionAddBankCard();

				break;
			case R.id.support_bank:
				SystemUtils.onEvent("Account_BankCard_Support", 1);
				card_numbered.setFocusable(false);
				card_verify_ed.setFocusable(false);
				hideSoftKeyboard();
				showBankdescDialog(ForTenderActivity.this, icon1,
						"请确保银行卡已开通认证支付,如未开通可到网银在线自行开通。(仅支持在PC浏览器开通)");
				break;
			case R.id.send_verify:
				actionSend_verify();
				break;
			case R.id.card_rl: // 银行卡类型
				Intent intent = new Intent(ForTenderActivity.this,
						CardTypeActivity.class);
				startActivityForResult(intent, 100);
				break;
			case R.id.support_phone:
				card_numbered.setFocusable(false);
				card_verify_ed.setFocusable(false);
				hideSoftKeyboard();
				showBankdescDialog(ForTenderActivity.this, icon2,
						"请输入在银行预留的手机号码,如忘记可登录网银-个人信息中查询");
				break;
			case R.id.card_numbered:
				card_numbered.setFocusable(true);
				card_numbered.setFocusableInTouchMode(true);
				card_numbered.requestFocus();
				break;

			case R.id.card_verify_ed:
				card_verify_ed.setFocusable(true);
				card_verify_ed.setFocusableInTouchMode(true);
				card_verify_ed.requestFocus();
				break;
			case R.id.ContentView:
				hideSoftKeyboard();
				break;
			case R.id.xiane_desc:
				Intent intent2 = new Intent(ForTenderActivity.this,
						KKDWebActivity.class);
				intent2.putExtra("url", com.kkd.kkdapp.Environment.getH5Url()
						+ "bankcard.html"); // 正式
				intent2.putExtra("useTitleName", true);
				intent2.putExtra("titleName", "支持的银行卡");
				startActivity(intent2);
				break;
			case R.id.agreement_tv2:

				break;

			case R.id.agreement_tv4:

				break;
			}

		}
	};

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		if (requestCode == 100 && resultCode == 1) {
			Bundle mBundle = data.getExtras();
			cardName = mBundle.getString("bankname");
			String bankimg = mBundle.getString("bankimg");
			// card_img.setImageResource(bankimg);
			ImageLoader.getInstance().displayImage(bankimg, card_img);
			card_img.setVisibility(View.VISIBLE);
			cardname_tv.setVisibility(View.VISIBLE);
			card_type.setVisibility(View.GONE);
			mCard_hint.setVisibility(View.GONE);
			cardname_tv.setText(cardName);
			// card_rl.setVisibility(View.VISIBLE);修改为不变化可见性
			card_rl.setBackgroundColor(Color.parseColor("#FFFFFF"));
		} else if (requestCode == KKDJiangXiWebActivity.SET_PWD) {
			if (resultCode == KKDJiangXiWebActivity.SET_PWD_SUCCESS) {// 江西银行设置交易密码页面的回调---成功
				getOther();
				dismissLoadIng();
				toStateAddedBank();
				desc_tv.setVisibility(View.GONE);
			}
		}
	}

	protected void actionAddBankCard() {
		SystemUtils.onEvent("Account_BankCard_Submit", 1);
		if (!TextUtils.isEmpty(truth_ed.getText().toString().trim())) {
			if (!TextUtils.isEmpty(card_ed.getText().toString().trim())) {
				if (!TextUtils.isEmpty(card_numbered.getText().toString()
						.trim())) {
					if (!TextUtils.isEmpty(card_verify_ed.getText().toString()
							.trim())) {
						if (!TextUtils.isEmpty(srvAuthCode)) {
							ShowLoadIng("开户中,请耐心等待....");
							// addBank();
							openAccount();
						} else {
							showToast("请获取验证码");
							// send_verify.setBackgroundResource(R.drawable.addbank_bg_tv);
							verfition_visibility.setTextColor(0xff6c54b6);
							verfition_visibility.setVisibility(View.VISIBLE);
							count_down.setVisibility(View.GONE);
							count_tv.setVisibility(View.GONE);
							flag = true;
							if (mTimerTask != null) {
								mTimerTask.cancel();
								mTimerTask = null;
							}
						}
					} else {
						showToast("请输入手机验证码");
					}
				} else {
					showToast("请输入您的银行卡号");
				}
			} else {
				showToast("请输入您的身份证号");
			}
		} else {
			showToast("请输入您的姓名");
		}
	}

	protected void actionSend_verify() {
		bankCode = CardNumberType.getCardType(cardName);
		if (flag) {
			if ("".equals(card_numbered.getText().toString())) {
				showToast(R.string.cardid_no);
			} else {
				if ("true".equals(luhmCheck(card_numbered.getText().toString()
						.replaceAll(" ", "")))) {
					if (bankCode == null) {
						showToast(R.string.select_card);
					} else {
						disposeSendVerify();
						// addBankVerification();
						sendSms();
						flag = false;
					}
				} else {
					showToast(luhmCheck(card_numbered.getText().toString()
							.replaceAll(" ", "")));
				}
			}
		}
	}

	protected void actionTrueId() {
		if ("".equals(truth_ed.getText().toString())) {
			showToast(R.string.trueIDVerifyActivity_name);
		} else if ("".equals(card_ed.getText().toString())) {
			showToast(R.string.trueIDVerifyActivity_card);
		} else {

			ShowLoadIng("实名中,请耐心等待.......");
			autonym();
		}
	}

	public void autonym() {

		KkdHttpMagager.getInstance().getTrueIDVerifyManager(
				truth_ed.getText().toString(), card_ed.getText().toString(),
				TrueIDVerifyData.class, new HttpCallBack() {

					@Override
					public void onSuccess(int statusCode, Object responseBody) {

						TrueIDVerifyData data = (TrueIDVerifyData) responseBody;
						String idCard = data.getIdCard();
						String realName = data.getRealName();
						User.updateCardId(idCard);
						User.updaterealName(realName);
						PreferenceUtils.getInstance().setAutonym(
								ForTenderActivity.this, 1);
						PreferenceUtils.getInstance().setIdCardAndRealName(
								ForTenderActivity.this, idCard, realName);
						mHandler.sendEmptyMessage(TRUE_ID_SUCCESS);

					}

					@Override
					public void onFailure(int statusCode, String desc) {
						Message msg = new Message();
						msg.what = TRUE_ID_FAILURE;
						msg.obj = desc;
						mHandler.sendMessage(msg);
					}
				});
	}

	/**
	 * ShowLoadIng:(这里用一句话描述这个方法的作用). <br/>
	 * 
	 * @author askzhao
	 * @param string
	 */
	protected void ShowLoadIng(String desc) {
		if (toLoadDialog != null) {
			toLoadDialog.dismiss();
			toLoadDialog = null;
		}
		toLoadDialog = DialogUtils.toLoadDialog(this, desc);

	}

	protected void dismissLoadIng() {
		if (toLoadDialog != null) {
			toLoadDialog.dismiss();
			toLoadDialog = null;
		}

	}

	/**** 隐藏软键盘 ************/
	public void hideSoftKeyboard() {
		SystemUtils.hideKeyBoard(ForTenderActivity.this);
	}

	/**
	 * 发送短信验证码
	 */
	private void sendSms() {
		KkdHttpMagager.getInstance().getSmsCodeApplyManager(
				card_obligate_numbered.getText().toString().trim(),
				"accountOpenPlus", String.class, new HttpCallBack() {

					@Override
					public void onSuccess(int statusCode, Object responseBody) {
						String responseString = responseBody.toString();
						JSONObject json;
						try {
							json = new JSONObject(responseString);
							srvAuthCode = json.getString("srvAuthCode");
							mHandler.sendEmptyMessage(ADDBANKVERIFICATION_CODE_ZERO);
						} catch (JSONException e) {
							e.printStackTrace();
						}
					}

					@Override
					public void onFailure(int statusCode, String desc) {
						Message msg = new Message();
						msg.what = ADDBANKVERIFICATION_CODE_ELSE;
						msg.obj = desc;
						mHandler.sendMessage(msg);
					}
				});
	}

	/**
	 * 绑定银行卡并发送验证码
	 */

	public void addBankVerification() {
		KkdHttpMagager.getInstance().getAddBankVerifitionManager(bankCode,
				card_numbered.getText().toString().replaceAll(" ", ""),
				card_obligate_numbered.getText().toString(), BankData.class,
				new HttpCallBack() {

					@Override
					public void onSuccess(int statusCode, Object responseBody) {
						BankData data = (BankData) responseBody;
						ticket = data.getTicket();
						bindingId = data.getBindingId();
						LogUtil.e("ticket1", ticket);
						LogUtil.e("bindingId1", bindingId);
						mHandler.sendEmptyMessage(ADDBANKVERIFICATION_CODE_ZERO);
					}

					@Override
					public void onFailure(int statusCode, String desc) {
						Message msg = new Message();
						msg.what = ADDBANKVERIFICATION_CODE_ELSE;
						msg.obj = desc;
						mHandler.sendMessage(msg);
					}
				});
	}

	/**
	 * 开户
	 */
	private void openAccount() {
		idCard_param = card_ed.getText().toString().trim();
		name_param = truth_ed.getText().toString().trim();
		bankCard_param = card_numbered.getText().toString().replaceAll(" ", "");
		KkdHttpMagager.getInstance().getAddNameBankManager(idCard_param,
				name_param, card_obligate_numbered.getText().toString().trim(),
				bankCard_param, srvAuthCode,
				card_verify_ed.getText().toString().trim(), bankCode,
				String.class, new HttpCallBack() {

					@Override
					public void onSuccess(int statusCode, Object responseBody) {
						String responseString = responseBody.toString();
						JSONObject json;
						try {
							json = new JSONObject(responseString);
							String desc = json.getString("desc");
							// 成功
							Message msg = new Message();
							msg.what = TRUE_ID_SUCCESS; // 添加银行卡code=其它;
							msg.obj = desc;
							mHandler.sendMessage(msg);
						} catch (JSONException e) {
							e.printStackTrace();
							Message msg = new Message();
							msg.what = TRUE_ID_FAILURE; // 添加银行卡code=其它;
							msg.obj = "网络异常";
							mHandler.sendMessage(msg);
						}
					}

					@Override
					public void onFailure(int statusCode, String desc) {
						Message msg = new Message();
						msg.what = TRUE_ID_FAILURE; // 添加银行卡code=其它;
						msg.obj = desc;
						mHandler.sendMessage(msg);
					}
				});
	}

	/**
	 * 绑定银行卡
	 */
	public void addBank() {

		KkdHttpMagager.getInstance().getAddBankManager(ticket,
				card_verify_ed.getText().toString(), bindingId, String.class,
				new HttpCallBack() {

					@Override
					public void onSuccess(int statusCode, Object res) {

						String responseString = res.toString();
						JSONObject json;
						try {
							json = new JSONObject(responseString);
							String desc = json.getString("desc");
							// 成功
							Message msg = new Message();
							msg.what = ADDBAND_CODE_ZERO; // 添加银行卡code=其它;
							msg.obj = desc;
							poi_pre_reward_image = json.optJSONObject("data")
									.optString("poi_pre_reward_image");
							poi_pre_reward_image2 = json.optJSONObject("data")
									.optString("poi_pre_reward_image2");
							cardNo = json.optJSONObject("data").optString(
									"cardNo");
							mHandler.sendMessage(msg);

						} catch (JSONException e) {
							e.printStackTrace();
							Message msg = new Message();
							msg.what = ADDBAND_CODE_ELSE; // 添加银行卡code=其它;
							msg.obj = "网络异常";
							mHandler.sendMessage(msg);
						}

					}

					@Override
					public void onFailure(int statusCode, String responseBody) {
						// TODO Auto-generated method stub
						Message msg = new Message();
						msg.what = ADDBAND_CODE_ELSE; // 添加银行卡code=其它;
						msg.obj = new String(responseBody);
						mHandler.sendMessage(msg);
					}
				});

	}

	/**
	 * 处理发送验证码按钮事件
	 */
	public void disposeSendVerify() {
		verfition_visibility.setVisibility(View.GONE);
		count_down.setVisibility(View.VISIBLE);
		count_tv.setVisibility(View.VISIBLE);
		time = 60;

		if (timer != null) {
			timer.cancel();
			timer = null;
		}
		timer = new Timer();

		if (mTimerTask != null) {
			mTimerTask.cancel();
			mTimerTask = null;
		}
		mTimerTask = new TimerTask() {

			@Override
			public void run() {
				handler.sendEmptyMessage(1);
			}
		};

		timer.schedule(mTimerTask, 0, 1000);

	}

	Handler handler = new Handler() {
		public void handleMessage(android.os.Message msg) {

			if (time != 0) {
				count_down.setText(time + "");
				time--;
			} else if (time == 0) {
				verfition_visibility.setVisibility(View.VISIBLE);
				count_down.setVisibility(View.GONE);
				count_tv.setVisibility(View.GONE);
				flag = true;
				if (mTimerTask != null) {
					mTimerTask.cancel();
					mTimerTask = null;
				}
			}
		};
	};

	/**
	 * 银行卡四位加空格
	 * 
	 * @param mEditText
	 */
	protected void bankCardNumAddSpace(final EditText mEditText) {
		mEditText.addTextChangedListener(new TextWatcher() {
			int beforeTextLength = 0;
			int onTextLength = 0;
			boolean isChanged = false;

			int location = 0;// 记录光标的位置
			private char[] tempChar;
			private StringBuffer buffer = new StringBuffer();
			int konggeNumberB = 0;

			@Override
			public void beforeTextChanged(CharSequence s, int start, int count,
					int after) {
				beforeTextLength = s.length();
				if (buffer.length() > 0) {
					buffer.delete(0, buffer.length());
				}
				konggeNumberB = 0;
				for (int i = 0; i < s.length(); i++) {
					if (s.charAt(i) == ' ') {
						konggeNumberB++;
					}
				}
			}

			@Override
			public void onTextChanged(CharSequence s, int start, int before,
					int count) {
				if (card_numbered.getText().toString().replaceAll(" ", "")
						.length() < 7) {
					cardtype = CardNumberType.getCardNumber(card_numbered
							.getText().toString().replaceAll(" ", ""));
				} else {
					cardtype = CardNumberType.getCardNumber(card_numbered
							.getText().toString().replaceAll(" ", "")
							.substring(0, 6));
				}
				card_rl.setClickable(true);
				LogUtil.e("cardtype", cardtype);
				if (cardtype != null) {
					cardName = cardtype;
					LogUtil.e("textvcard_numberediew", cardName);
					if ("农业银行".equals(cardName)) {
						card_img.setImageResource(R.drawable.agriculture_logo);
					} else if ("建设银行".equals(cardName)) {
						card_img.setImageResource(R.drawable.construction_logo);
					} else if ("北京银行".equals(cardName)) {
						card_img.setImageResource(R.drawable.peking_logo);
					} else if ("渤海银行".equals(cardName)) {
						card_img.setImageResource(R.drawable.bohai_logo);
					} else if ("工商银行".equals(cardName)) {
						card_img.setImageResource(R.drawable.commerce_logo);
					} else if ("光大银行".equals(cardName)) {
						card_img.setImageResource(R.drawable.brighten_logo);
					} else if ("广发银行".equals(cardName)) {
						card_img.setImageResource(R.drawable.wide_logo);
					} else if ("交通银行".equals(cardName)) {
						card_img.setImageResource(R.drawable.traffic_logo);
					} else if ("民生银行".equals(cardName)) {
						card_img.setImageResource(R.drawable.livelihood_logo);
					} else if ("南京银行".equals(cardName)) {
						card_img.setImageResource(R.drawable.nanjing_logo);
					} else if ("浦东发展银行".equals(cardName)) {
						card_img.setImageResource(R.drawable.pudong_logo);
					} else if ("兴业银行".equals(cardName)) {
						card_img.setImageResource(R.drawable.business_logo);
					} else if ("中国邮储银行".equals(cardName)) {
						card_img.setImageResource(R.drawable.postal_logo);
					} else if ("招商银行".equals(cardName)) {
						card_img.setImageResource(R.drawable.attract_logo);
					} else if ("浙商银行".equals(cardName)) {
						card_img.setImageResource(R.drawable.zhejiang_logo);
					} else if ("中国银行".equals(cardName)) {
						card_img.setImageResource(R.drawable.china_logo);
					} else if ("平安银行".equals(cardName)) {
						card_img.setImageResource(R.drawable.safeness_logo);
					} else if ("中信银行".equals(cardName)) {
						card_img.setImageResource(R.drawable.citic_logo);
					} else if ("华夏银行".equals(cardName)) {
						card_img.setImageResource(R.drawable.huaxia_logo);
					}
					card_img.setVisibility(View.VISIBLE);
					cardname_tv.setVisibility(View.VISIBLE);
					card_type.setVisibility(View.GONE);
					mCard_hint.setVisibility(View.GONE);
					cardname_tv.setText(cardName);
					// card_rl.setVisibility(View.VISIBLE);修改为不变化可见性
					card_rl.setBackgroundColor(Color.parseColor("#FFFFFF"));
					cardname_tv.setTextColor(Color.parseColor("#343434"));
					flag = true;
					if (cardList != null) {
						for (int i = 0; i < cardList.size(); i++) {
							if (cardName.equals(cardList.get(i).getBankName())) {
								if (cardList.get(i).getBindCardStatus()
										.equals("0")) {
									cardname_tv
											.setText("由于新浪支付业务调整，暂停此银行绑卡服务，请使用其他银行储蓄卡进行绑定");
									cardname_tv.setTextColor(Color
											.parseColor("#FFFFFF"));
									card_rl.setBackgroundResource(R.drawable.back_mongolia);
									card_rl.setClickable(false);
									flag = false;
									verfition_visibility
											.setTextColor(0xffb5b5b5);
									verfition_visibility
											.setVisibility(View.VISIBLE);
								}
							}
						}
					}
				} else {

					if (card_numbered.getText().toString().replaceAll(" ", "")
							.length() >= 10) {
						LogUtil.e("length", ""
								+ card_numbered.getText().toString()
										.replaceAll(" ", "").length());
						if (cardName == null) {
							card_img.setVisibility(View.GONE);
							cardname_tv.setVisibility(View.GONE);
							card_type.setVisibility(View.VISIBLE);
							mCard_hint.setVisibility(View.VISIBLE);
							// card_rl.setVisibility(View.VISIBLE);修改为不变化可见性
							mCard_hint
									.setText("新浪支付暂不支持此银行绑卡服务，请更换其他银行储蓄卡进行绑定");
							mCard_hint.setTextColor(Color.parseColor("#FFFFFF"));
							card_rl.setBackgroundResource(R.drawable.back_mongolia);
						}
					} else if (card_numbered.getText().toString()
							.replaceAll(" ", "").length() < 3) {
						// card_rl.setVisibility(View.GONE);修改为不变化可见性
						card_img.setVisibility(View.GONE);
						cardname_tv.setVisibility(View.GONE);
						card_type.setVisibility(View.VISIBLE);
						mCard_hint.setVisibility(View.VISIBLE);
					}
				}
				if ("".equals(card_numbered.getText().toString())) {
					// card_rl.setVisibility(View.GONE);修改为不变化可见性
					cardName = null;
				}

				onTextLength = s.length();
				buffer.append(s.toString());
				if (onTextLength == beforeTextLength || onTextLength <= 3
						|| isChanged) {
					isChanged = false;
					return;
				}
				isChanged = true;
			}

			@Override
			public void afterTextChanged(Editable s) {
				if (isChanged) {
					location = mEditText.getSelectionEnd();
					int index = 0;
					while (index < buffer.length()) {
						if (buffer.charAt(index) == ' ') {
							buffer.deleteCharAt(index);
						} else {
							index++;
						}
					}

					index = 0;
					int konggeNumberC = 0;
					while (index < buffer.length()) {
						if ((index == 4 || index == 9 || index == 14 || index == 19)) {
							buffer.insert(index, ' ');
							konggeNumberC++;
						}
						index++;
					}

					if (konggeNumberC > konggeNumberB) {
						location += (konggeNumberC - konggeNumberB);
					}

					tempChar = new char[buffer.length()];
					buffer.getChars(0, buffer.length(), tempChar, 0);
					String str = buffer.toString();
					if (location > str.length()) {
						location = str.length();
					} else if (location < 0) {
						location = 0;
					}

					mEditText.setText(str);
					Editable etable = mEditText.getText();
					Selection.setSelection(etable, location);
					isChanged = false;
				}
			}
		});
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.kkd.kkdapp.base.BaseActivity#onDestroy()
	 */
	@Override
	protected void onDestroy() {
		super.onDestroy();
		if (mDialog != null) {
			mDialog.cancel();
			mDialog = null;
		}
		if (dialog_registerSuccess != null) {
			dialog_registerSuccess.cancel();
			dialog_registerSuccess = null;
		}
		if (mTimerTask_newTask != null) {
			mTimerTask_newTask.cancel();
			mTimerTask_newTask = null;
		}
		if (mTimer != null) {
			mTimer.cancel();
			mTimer = null;
		}
		dismissLoadIng();
	}

	/**
	 * 
	 * 判断是否设置交易密码
	 */
	public void requestIsSetPayPassword() {
		KkdHttpMagager.getInstance().getWithdrawUpdateManager(String.class,
				new HttpCallBack() {

					@Override
					public void onSuccess(int statusCode, Object responseBody) {
						try {
							String responseString = responseBody.toString();
							JSONObject data = new JSONObject(responseString);
							LogUtil.i("测试", "1");
							int isPayPassword = data.getInt("isPayPassword");
							if (isPayPassword == 1) {
								PreferenceUtils.getInstance()
										.setWithdrawPassWord(mContext, 1);
								Intent intent = new Intent(mContext,
										WithdrawActivity.class);
								startActivity(intent);
								finish();
							} else {
								PreferenceUtils.getInstance()
										.setWithdrawPassWord(mContext, 0);
								isDialog();
							}
						} catch (JSONException e) {

							e.printStackTrace();
						}
						dismissLoadIng();
					}

					@Override
					public void onFailure(int statusCode, String desc) {
						dismissLoadIng();
						showToast(desc);
					}
				});
	}

	public void isDialog() {
		if (dialog1 != null) {
			dialog1.cancel();
			dialog1 = null;
		}
		dialog1 = DialogUtils.deleteBankDialog(mContext, "您尚未设置提现密码，请先去设置提现密码",
				new OnClickListener() {

					@Override
					public void onClick(View v) {
						switch (v.getId()) {
						case R.id.confirm_deletebank:
							Intent intent = new Intent(mContext,
									SetDealActivity.class);
							intent.putExtra("setFlag", 1);
							startActivity(intent);
							if (dialog1 != null) {
								dialog1.dismiss();
							}
							finish();
							break;
						case R.id.cancel_deletebank:
							if (dialog1 != null) {
								dialog1.dismiss();
							}
							finish();
							break;
						}
					}
				});
		dialog1.setCancelable(false);
		dialog1.show();

	}

	public void showDialog(String message) {
		if (mDialog2 != null) {
			mDialog2.cancel();
			mDialog2 = null;
		}
		mDialog2 = DialogUtils.generateDialog(mContext, message,
				new OnClickListener() {

					@Override
					public void onClick(View v) {
						mDialog2.dismiss();
					}
				});
		mDialog2.show();
	}

	/**
	 * getOther:(更新other信息). <br/>
	 * 
	 * @author askzhao
	 */
	private void getOther() {
		String customerIdAndToken = PreferenceUtils.getInstance()
				.getcustomerId(this);
		String[] cat = customerIdAndToken.split("&");
		if (cat == null || cat.length < 2)
			return;
		KkdHttpMagager.getInstance().activityConfig(TyjConfigEntity.class,
				new HttpCallBack() {

					@Override
					public void onSuccess(int statusCode, Object responseBody) {
						// 更新数据
						try {
							PreferenceUtils.getInstance().updateHomeOtherData(
									ForTenderActivity.this,
									((TyjConfigEntity) responseBody)
											.getTyjConfig());
							poiPreMisPacketTips = ((TyjConfigEntity) responseBody)
									.getPoiPreMisPacketTips();
							newMisTips = ((TyjConfigEntity) responseBody)
									.getNewMisTips().getNewMisTips();
							maxTime = (int) (((TyjConfigEntity) responseBody)
									.getNewMisTips().getTimeSpace() / 1000);
							mHandler.sendEmptyMessage(UPDATE_UI);
						} catch (Exception e) {
							// 忽略
							e.printStackTrace();
						}
					}

					@Override
					public void onFailure(int statusCode, String desc) {
						// 啥也不用做

					}
				});
	}

	// 支持的银行卡
	public void questCardList() {
		KkdHttpMagager.getInstance().postCard(new TypeToken<List<CardItem>>() {
		}.getType(), new HttpCallBack() {

			@Override
			public void onSuccess(int statusCode, Object responseBody) {
				cardList = (List<CardItem>) responseBody;
			}

			@Override
			public void onFailure(int statusCode, String desc) {
			}
		});
	}

	public int maxTime = 0;
	private int mRecordTime = 0;
	private boolean isRecoding = false;
	public static final int RECORD_TIMER = 8112;
	public static final int RECORD_DONE = 8113;
	public static final int RECORD_ERROR = 8114;
	public static final int PERIOD = 1000;
	private TimerTask mTimerTask_newTask = null;
	private Timer mTimer = new Timer();
	public TimerHandler mTimerHandler = new TimerHandler(this);

	public void updateNewTaskSpaceTime() {
		int dtime = maxTime - mRecordTime;
		int ss = dtime % 60;
		int mm = (dtime / 60) % 60;
		int hh = dtime / 60 / 60;
		String tip_time_newtask = "";
		if (hh < 1) { // 不足一小时
			tip_time_newtask = mm + "分" + ss + "秒后";
		} else if (hh >= 1 && hh < 24) { // 小于一天大于1小时
			tip_time_newtask = "今天24时";
		} else if (hh >= 24) { // 大于一天
			tip_time_newtask = hh / 24 + "天后";
		}
		tv_time_newTask.setText(tip_time_newtask);
	}

	public void onTimerFinish() {
		if (mTimerTask_newTask != null) {
			mTimerTask_newTask.cancel();
			mTimerTask_newTask = null;
		}
		if (mTimer != null) {
			mTimer.cancel();
			mTimer = null;
		}
		getOther();
	}

	public void startTime() {
		mRecordTime = 0;
		if (!isRecoding) {
			if (mTimerTask_newTask != null) {
				mTimerTask_newTask.cancel();
				mTimerTask_newTask = null;
			}
			if (mTimer != null) {
				mTimer.cancel();
				mTimer = null;
			}
			mTimerTask_newTask = new RecordTimeTask();
			mTimer = new Timer();
			mTimer.schedule(mTimerTask_newTask, 0, PERIOD);
		}

		isRecoding = true;

	}

	private class RecordTimeTask extends TimerTask {
		@Override
		public void run() {
			if (isRecoding) {
				mRecordTime++;
				if (mRecordTime <= maxTime) {
					Message message = new Message();
					message.what = RECORD_TIMER;
					message.obj = mRecordTime;
					mTimerHandler.sendMessage(message);
				} else {
					Message message = new Message();
					message.what = RECORD_DONE;
					message.arg1 = mRecordTime;
					message.obj = "";
					mTimerHandler.sendMessage(message);
					isRecoding = false;
				}
			}

		}
	}

	public static class TimerHandler extends Handler {
		WeakReference<ForTenderActivity> reference;

		public TimerHandler(ForTenderActivity activity) {
			reference = new WeakReference<ForTenderActivity>(activity);
		}

		@Override
		public void dispatchMessage(Message msg) {
			switch (msg.what) {
			case RECORD_TIMER:
				if (reference != null && reference.get() != null)
					reference.get().updateNewTaskSpaceTime();
				break;
			case RECORD_DONE:
				if (reference != null && reference.get() != null)
					reference.get().onTimerFinish();
				break;
			default:
				break;
			}
		}
	}

	private void showTipForTrueIdSucess() {
		final AlphaAnimation alphaAnimation_in = new AlphaAnimation(0, 1);
		alphaAnimation_in.setFillAfter(true);
		alphaAnimation_in.setDuration(1000);
		final AlphaAnimation alphaAnimation_out = new AlphaAnimation(1, 0);
		alphaAnimation_out.setFillAfter(true);
		alphaAnimation_out.setDuration(1000);
		rel_toStateBankcard.startAnimation(alphaAnimation_in);
		rel_new_task.startAnimation(alphaAnimation_out);
		rel_toStateBankcard.setVisibility(View.VISIBLE);
		mHandler.postDelayed(new Runnable() {

			@Override
			public void run() {
				rel_toStateBankcard.startAnimation(alphaAnimation_out);
				rel_new_task.startAnimation(alphaAnimation_in);
			}
		}, 2500);
		mHandler.postDelayed(new Runnable() {

			@Override
			public void run() {
				rel_toStateBankcard.setVisibility(View.GONE);
			}
		}, 3500);
	}

	/**
	 * 设置江西银行交易密码
	 */
	private void setJiangXiPassword() {
		KkdHttpMagager.getInstance().getJiangXiPassword(
				JiangXiSetPasswordData.class, new HttpCallBack() {

					@Override
					public void onSuccess(int statusCode, Object responseBody) {
						JiangXiSetPasswordData data = (JiangXiSetPasswordData) responseBody;
						poi_pre_reward_image = data.getPoi_pre_reward_image();
						poi_pre_reward_image2 = data.getPoi_pre_reward_image2();
						Message msg = new Message();
						msg.what = SETPASS_CODE_SUC;
						msg.obj = data.getHtml();
						mHandler.sendMessage(msg);
					}

					@Override
					public void onFailure(int statusCode, String desc) {
						Message msg = new Message();
						msg.what = SETPASS_CODE_ELSE;
						msg.obj = desc;
						mHandler.sendMessage(msg);
					}
				});
	}

}
